package net.xconcepts.stockdata.model.analysis;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import net.xconcepts.stockdata.model.analysis.symbol.Symbol;
import net.xconcepts.stockdata.model.tick.SymbolTick;

/**
 * Rules are combined using AND. IE all rules must be satisfied for a symbol
 * to get through the filter.
 * 
 * @author Steven
 *
 */
public class SymbolFilter {

	private final Collection<Rule<?>> mRules = new LinkedList<Rule<?>>();
	
	public SymbolFilter(Rule<?> rule) {
		mRules.add(rule);
	}
	
	public Map<Symbol, SymbolTick> processTicks(Map<Symbol, SymbolTick> ticks) {
		Map<Symbol, SymbolTick> filteredTicks = new HashMap<Symbol, SymbolTick>();
		
			for(Rule<?> rule : mRules) {
				Map<Symbol, Boolean> ruleResults = rule.processTicks(ticks);
				for(Symbol symbol : ruleResults.keySet()) {
					if(ruleResults.get(symbol)) {
						filteredTicks.put(symbol, ticks.get(symbol));
					}
				}				
			}
		
		return filteredTicks;
	}
}
